package cn.schoolwow.workflow.module.task.action.flow.common;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.deploy.DeployNodeType;
import cn.schoolwow.workflow.domain.task.TaskType;
import cn.schoolwow.workflow.entity.WorkFlowNode;
import cn.schoolwow.workflow.module.task.action.flow.complete.nodeType.general.HandleEndNodeFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.transaction.InsertWorkFlowTaskFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.transaction.UpdateWorkFlowInstanceAndTaskFlow;

public class AutomaticPassNodeCommonFlow implements BusinessFlow {

    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.executeFlowList(new UpdateWorkFlowInstanceAndTaskFlow());

        WorkFlowNode passNode = flowContext.checkData("passNode", WorkFlowNode.class);

        DeployNodeType deployNodeType = DeployNodeType.getDeployNodeType(passNode.getType());
        switch (deployNodeType) {
            case EndNode: {
                flowContext.executeFlowList(new HandleEndNodeFlow());
                return;
            }
        }

        flowContext.startFlow(new SetNextNodeCommonFlow())
                .next(new InsertWorkFlowTaskFlow())
                .putCurrentCompositeFlowData("currentWorkflowNode", passNode)
                .putCurrentCompositeFlowInstanceData(TaskType.COMPLETE)
                .execute();
    }

    @Override
    public String name() {
        return "自动通过当前节点-处理下一个节点";
    }
}
